/*
 * Powered By fanrenqij.com
 * Since 2017 - 2017
 */

package com.fanrenqiji.modules.business.eventcase.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.entity.EventCaseEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 持久化接口
 */
public interface EventCaseDao extends EventCaseDaoCustom, CrudRepository<EventCaseEntity, Long> {

    @Query("from EventCaseEntity where delFlag='" + EventCaseEntity.DEL_FLAG_NORMAL + "' order by id desc")
    List<EventCaseEntity> findAllList();


    @Query("from EventCaseEntity where delFlag='" + EventCaseEntity.DEL_FLAG_NORMAL + "' and status =?1 order by id")
    List<EventCaseEntity> findEventCaseEntityByStatus(int status);

    @Query("from EventCaseEntity where delFlag='" + EventCaseEntity.DEL_FLAG_NORMAL + "' and event.id =?1  and parent.id=?2 and semester.id=?3 and createDate between ?4 and ?5 order by id")
    List<EventCaseEntity> findEventCase(Long eventId, Long parentId, Long semesterId, Date start, Date end);

    @Modifying
    @Query("update EventCaseEntity set delFlag='" + EventCaseEntity.DEL_FLAG_DELETE + "' where id = ?1 ")
    void deleteById(Long id);

}


interface EventCaseDaoCustom extends BaseDao<EventCaseEntity> {
}

@Repository
class EventCaseDaoImpl extends BaseDaoImpl<EventCaseEntity> implements EventCaseDaoCustom {

}
